/**
 * Created by huzhihui on 2016/11/22.
 */
var layerLoad;
var layerNumber;
$(function(){
    initProductTypeList(1);
    /**
     * 商品类型--列表查询
     */
    function initProductTypeList(currentPage){
    	if(currentPage == 1){
    		currentPageNow = currentPage;
    	}
        var sysProductType = {
            currentPage : currentPage,
        };
        $.ajax({
            url : $api.postReview.selectPosterReviews,
            type : "POST",
            dataType : "JSON",
            contentType : 'application/json',
            data :  JSON.stringify(sysProductType),
            beforeSend : function () {
                layerLoad = layer.load();
            },
            success : function(data) {
                if(!$checkRemouteStatus(data)){
                    layer.close(layerLoad);
                    return;
                }
                var dataObj=data.msg;
                var listTxt="";
                $.each(dataObj,function(index,item){
                    listTxt+="<tr><td class='am-text-truncate am-tab-width-min'>"+item.orderSn+"</td>";
                    listTxt+="<td class='am-text-truncate am-tab-width-min'>"+item.memberName+"</td>";
                    listTxt+="<td class='am-text-truncate am-tab-width-min'>"+item.adminName+"</td>";
                    listTxt+="<td class='am-text-truncate am-tab-width-min am-text-center'>";
                    for(var i=1;i<=item.score;i++){
                        listTxt+="<img src='../assets/i/smallStart1.webp'>";
                    }
                    for(var i=5;i > item.score;i--){
                        listTxt+="<img src='../assets/i/smallStart0.webp'>";
                    }
                    listTxt+="</td><td class='am-text-truncate am-tab-width-min am-text-center'>";
                    for(var i=1;i<=item.postScore;i++){
                        listTxt+="<img src='../assets/i/smallStart1.webp'>";
                    }
                    for(var i=5;i > item.postScore;i--){
                        listTxt+="<img src='../assets/i/smallStart0.webp'>";
                    }
                    listTxt+="</td><td class='am-center wid100'><div class='am-btn-group am-btn-group-xs wid100'>";
                    if(item.content===""){
                        item.content="该用户没有评论";
                    }
                    var createDate=item.createDate.split(" ");
                    listTxt+="<input type='button' class='am-btn am-btn-success btn-order-list-detail' createDate =" + createDate[0] + " content ="+item.content+" value='评价详情'>";
                    listTxt+="</div></td></tr>";
                });
                $("#comment-body").html(listTxt);
                /*分页*/
                layui.use('laypage', function() {
                    layui.laypage({
                        cont: $('#system-admin-page'),
                        pages: data.totalPage,
                        groups: 2,
                        curr: data.currentPage,
                        skip: true,
                        skin:'#0e90d2',
                        jump: function (obj,first) {
                            if(!first){
                                initProductTypeList(obj.curr);
                            }
                        }
                    });
                });
                layer.close(layerLoad);
            },
    		error : function() {
    			layer.close(layerLoad);
    			layer.msg('网络异常，请稍后再试', {icon: 2});
    		}
        });
    };
    /**
     * 商品类型--单个详情查询
     */
    $('#comment-body').on('click', '.btn-order-list-detail', function() {
        $("#createDateBox").text($(this).attr("createDate"));
        $("#contentBox").text($(this).attr("content"));
        layerNumber=layer.open({
            type : 1,
            title : '评论详情',
            area : 'auto',
            maxWidth : '1000px',
            closeBtn:1,
            content : $('#system-product-category-update-model'),
            cancel : function(){
                $('#sys-product-form-update')[0].reset();
            }
        });
    });

});
$("#save").click(function(){
    layer.close(layerNumber);
});